/**
 * token 管理，认证相关
 * sessionStorage.getItem('cpasToken') as string;
 */

import { isRunInFrame } from '@/utils/env';

const TokenKey = 'cpasToken'; // cpas_token
const storage = isRunInFrame ? sessionStorage : localStorage; // sessionStorage localStorage(可共享给子系统)
// 获取当前token
const getToken = (): string => {
  return storage.getItem(TokenKey) as string;
};
// 设置 当前登录成功后的token
function setToken(tokenID: string) {
  storage.setItem(TokenKey, tokenID);
}
// 删除 当前token
function removeToken() {
  return storage.removeItem(TokenKey);
}

export default getToken;
export { TokenKey, setToken, removeToken };
